package com.book.web;

import com.book.service.AdminService;
import com.book.service.impl.AdminServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/adminAddBookServlet")
public class AdminAddBookServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        String bookName = request.getParameter("bookName");
        String bookAuthor = request.getParameter("bookAuthor");
        String bookType = request.getParameter("bookType");
        int amount = Integer.parseInt(request.getParameter("amount"));
        int number = Integer.parseInt(request.getParameter("number"));
        AdminService adminService = new AdminServiceImpl();
        boolean b = adminService.addBook(bookName, bookAuthor, bookType, amount, number);
        if (b) {
            response.sendRedirect(request.getContextPath()+"/adminFindBookServlet");
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
